<template>
  <component :is="currentComponent?.component"></component>
</template>

<script setup lang="ts">
import { getFileName } from "@/utils/reg";
import { currentShape } from "@/views/paint/modules/data/shapes";

// 批量导入组件,必须以类型+config命名
const components = import.meta.glob("./**.vue");
const componentList = ref([] as Array<any>);
for (const [key, value] of Object.entries(components)) {
  componentList.value.push({
    type: getFileName(key).toLowerCase().replace("config", ""),
    component: markRaw(defineAsyncComponent(value as any))
  });
}
const currentComponent = computed(() => {
  return componentList.value.find((com: any) => {
    if (currentShape.value.type.replace("d-", "") === com.type) {
      return com;
    }
    return null;
  });
});
</script>

<style lang="scss" scoped></style>
